﻿using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using InnovTech.Wpf.Util;


namespace InnovTech.Util.Test.Xaml
{
    /// <summary>
    /// Summary description for TestXamlUtil
    /// </summary>
    [TestClass]
    public class TestXamlUtil
    {
        public TestXamlUtil()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestGetObjectFromXamlFile()
        {
            //Assembly assembly = Assembly.GetAssembly(this.GetType());
            //string outPutPath = Path.GetDirectoryName(assembly.Location);
            //XamlUtil.GetObjectFromXamlFile(Output + "\\Resource\\TextFile1.txt");
        }

        [TestMethod]
        public void TestGetObjectFromXamlContentString()
        {
            FileInfo file = new FileInfo(Output + "\\Resource\\TextFile1.txt");
            FileStream stream = file.OpenRead();
            byte[] content = new byte[stream.Length];
            stream.Read(content, 0, (int)stream.Length);
            string xamlContent = System.Text.ASCIIEncoding.Default.GetString(content);
            XamlUtil.GetObjectFromXamlContentString(xamlContent);
        }

        private string Output
        {
            get
            {
                Assembly assembly = Assembly.GetAssembly(this.GetType());
                string outPutPath = Path.GetDirectoryName(assembly.Location);
                return outPutPath;
            }
        }
    }
}
